.DEFAULT_GOAL := build
current_dir_name = $(notdir $(CURDIR))
GFCLI=/Users/larry/Documents/Tools/gfv2

# Build binary using configuration from hack/config.yaml.
.PHONY: build
build: 
	$(GFCLI) build -ew

# Parse api and generate controller/sdk.
.PHONY: ctrl
ctrl:
	@if [ -z "$(name)" ]; then \
		$(GFCLI) gen ctrl; \
	else \
		$(GFCLI) gen ctrl --srcFolder "addons/$(name)/api" --dstFolder "addons/$(name)/controller"; \
	fi


# Generate Go files for DAO/DO/Entity.
.PHONY: dao
dao: 
	$(GFCLI) gen dao

# Parse current project go files and generate enums go file.
.PHONY: enums
enums: 
	$(GFCLI) gen enums

# Generate Go files for Service.
.PHONY: service
service:
	@if [ -z "$(name)" ]; then \
		$(GFCLI) gen service; \
	else \
		$(GFCLI) gen service -s "addons/$(name)/logic" -d "addons/$(name)/service"; \
	fi

# Parsing protobuf files and generating go files.
.PHONY: pb
pb: 
	@$(GFCLI) gen pb

# Generate protobuf files for database tables.
.PHONY: pbentity
pbentity: 
	$(GFCLI) gen pbentity

.PHONY: sql
sql:
	@if [ -z "$(addon)" ]; then \
		migrate create -ext sql -dir "internal/migrations" -seq $(name); \
	else \
		migrate create -ext sql -dir "addons/$(addon)/sql_$(addon)" -seq $(name); \
	fi

.PHONY: migrate
migrate:
	@if [ -z "$(addon)" ]; then \
		$(GFCLI) pack "internal/migrations" "internal/packed/migrations.go"; \
	else \
		$(GFCLI) pack "addons/$(addon)/sql_$(addon)" "addons/$(addon)/packed/migrations.go"; \
	fi

